﻿using DoNet.Handlers.Events;
using DoNet.EventBus.Abstractions;
using DoNet.System.IServices;
using DoNet.System.Models;
using DoNet.ThirdParty.AutoMapper;

namespace DoNet.Handlers.Handlers
{
    /// <summary>
    /// 访问日志事件
    /// </summary>
    public class VisitLogIntegrationEventHandler : IIntegrationEventHandler<VisitLogIntegrationEvent>
    {
        private readonly IVisitLogService _visitLogService;
        public VisitLogIntegrationEventHandler(IVisitLogService visitLogService)
        {
            _visitLogService = visitLogService;
        }

        public async Task Handle(VisitLogIntegrationEvent @event)
        {
            var visitLog = @event.MapTo<VisitLog>();
            if (visitLog != null)
            {
                await _visitLogService.InsertAsync(visitLog);
            }
        }
    }
}
